package com.layui.ad.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.layui.ad.annotation.DataSource;
import com.layui.ad.entity.Article;
import com.layui.ad.entity.Community;
import com.layui.ad.enums.DataSourceEnum;
import com.layui.ad.mapper.CommunityMapper;
import com.layui.ad.query.CommunityQuery;
import com.layui.ad.service.CommunityService;
import com.layui.ad.utils.JsonResult;
import com.layui.ad.vo.CommunityListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community> implements CommunityService {
//    public class CommunityServiceImpl implements CommunityService {
    @Autowired
    private CommunityMapper communityMapper;


    @Override
    @DataSource(DataSourceEnum.BROKER)
    public JsonResult getRecordList(CommunityQuery communityQuery) {
        PageHelper.startPage(communityQuery.getPage(),communityQuery.getLimit());
        List<CommunityListVo> objList = communityMapper.selectRecordList(communityQuery);
        PageInfo<CommunityListVo> pageInfo = new PageInfo<>(objList);
        return JsonResult.ok("", objList, pageInfo.getTotal());
    }


    @Override
    @DataSource(DataSourceEnum.BROKER)
    public JsonResult getAllByPage(CommunityQuery communityQuery){
        PageHelper.startPage(communityQuery.getPage(),communityQuery.getLimit());
        List<Community> objList = communityMapper.selectAllByPage();
        PageInfo<Community> pageInfo = new PageInfo<>(objList);
        return JsonResult.ok("",objList,pageInfo.getTotal());
    }


    @Override
    @DataSource(DataSourceEnum.BROKER)
    public Map<String,Object> getAllByPageMap(CommunityQuery communityQuery){
        PageHelper.startPage(communityQuery.getPage(),communityQuery.getLimit());
        List<Community> objList = communityMapper.selectAllByPage();
        PageInfo<Community> pageInfo = new PageInfo<>(objList);
        Map<String,Object> map = new HashMap<>();
        map.put("data",objList);
        map.put("count",pageInfo.getTotal());
        return map;

    }
}
